import { Button, Form, message } from "antd";
import { ProductItemCreateDto } from "@/definition/dto/ProductDto";
import { useEffect, useState } from "react";
import { FormItemInput,FormItemSearch, FormItemUpload, FormItemRadio, FormInputNumber, FormItemButton } from "@components/antd/form/index";
import { ProductItemStatus } from "@enum/ProductEnum";
import { API } from "@/request/api";
import { useParams,useNavigate } from "react-router-dom";
import { ProductMenuVo } from "@/definition/vo/ProductVo";
const ProductItemDetails = () => {
    const {id = ''} = useParams();
    const navigate = useNavigate();
    const [form] = Form.useForm<ProductItemCreateDto>();
    const url = "//v1.cdn.soiiy.cn/preview/00-7e6b/bWlsbGlzPTE2Njk1MzU3MTMwMDUmcmFuZG9tPWZkNjdkOWM5LTU4YTMtNDMzZS04YjRlLWUxNDBiODNjYTkzYw"
    const getItemDetails = async () =>{
      const res = await API.queryProdutItem(id)
      form.setFieldsValue(res);
    }

    form.setFieldValue("coverUrl",url);

    const onComfirm = async () =>{
       await API.createProductItem(form.getFieldsValue());
        message.success("创建成功");
        navigate('/products/items');
    }
    const onReset = () => {

    }

    useEffect(() => {
        id && getItemDetails();
    }, []);

    return (
        <>
            <Form labelCol={{ span: 2 }} form={form}>
                <FormItemSearch require name="menu" label="商品类型" api="queryProductMenuItems" valueKey="menu" labelKey="menu" />
                <FormItemInput require name="title" label="商品名称" />
                <FormItemInput require name="description" label="商品描述" />
                <FormItemInput require name="code" label="商品编码" />
                <FormInputNumber require name="sort" label="排序值" />
                <FormInputNumber require name="price" label="商品价格" />
                <FormInputNumber require name="stockTotal" label="商品库存" />
                <FormItemUpload name="coverUrl" label="封面图" filelist={[url]} onUpload={() => { }} />
                <FormItemRadio name="status" label="状态" options={ProductItemStatus} />
                <FormItemButton offset={2} onReset={onReset} onConfirm={onComfirm}></FormItemButton>
            </Form>
        </>
    )
}
export default ProductItemDetails;